package net.atomarrow.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
/**
 * properties配置工具类
 * @author Michael
 *
 */
public class PropertyUtil {

    public static Properties readProperties(String path) {
        Properties properties = new Properties();
        InputStream is = null;
        try {
            is = new FileInputStream(new File(path));
            properties.load(is);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return properties;
    }

    public static void writeProperties(String path, Properties properties) {
       writeProperties(path, properties, null);
    }
    public static void writeProperties(String path, Properties properties,String remark) {
        OutputStream os = null;
        try {
            os = new FileOutputStream(new File(path));
            properties.store(os, remark);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (os != null) {
                    os.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
